package LuoGu.搜索.全排列;

import java.io.*;

public class Temp {
    static PrintWriter p = new PrintWriter(new BufferedOutputStream(System.out));
    static boolean [] check;
    static int [] temp;
    static int n;
    public static void main(String[] args) throws IOException {
        StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        st.nextToken();
        n = (int) st.nval;
        check = new boolean[n+1];
        temp = new int[n+1];
        dfs(1);
        p.flush();
    }

    public static void dfs(int first){
        if(first>n){
            for(int i=1;i<n+1;i++){
                p.print(String.format("%5d",temp[i]));
            }
            p.println();
        }
        else {
            for(int i=1;i<=n;i++){
                if(check[i]==false){
                    check[i] = true;
                    temp[first] = i;
                    dfs(first+1);
                    check[i] = false;
                }
            }
        }
    }
}
